<template>
  <div>
    <movies-search></movies-search>
    <movies-group :groupList="groupList" :groupTitle="groupTitle"></movies-group>
  </div>
</template>

<script>
import MoviesSearch from './components/Search'
import MoviesGroup from './components/Group'
import {getMovieHomeInfo} from 'api/complex'
export default {
  name: 'Movies',
  data () {
    return {
      groupList: [],
      groupTitle: [],
      groupParams: {
        'in_theaters': '正在热映',
        'coming_soon': '即将上映',
        'top250': 'TOP250'
      }
    }
  },
  components: {
    MoviesSearch,
    MoviesGroup
  },
  methods: {
    _getMovieHomeInfo () {
      for (let key in this.groupParams) {
        getMovieHomeInfo(key).then((res) => {
          if (res.status === 200) {
            res = res.data
            this.groupTitle.push([key, this.groupParams[key]])
            this.groupList.push(res.subjects)
          }
        })
      }
    }
  },
  mounted () {
    this._getMovieHomeInfo()
  }
}
</script>

<style>

</style>
